From 9333781f509b67bf5c08a790664a660bab3dc819 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Thu, 24 Nov 2011 15:49:25 +0000 Subject: [PATCH] waitqueue: Reorder prepare_to_wait() so that vcpu is definitely on the queue on exit, even after a wakeup. Otherwise, when we go round the loop in wait_event(), we may not actually sleep after the first iteration, as we do not put ourselves back on the queue on wakeup. Signed-off-by: Keir Fraser --- xen/common/wait.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xen/common/wait.c b/xen/common/wait.c index cf515b1aee..b125dc5be2 100644 --- a/xen/common/wait.c +++ b/xen/common/wait.c @@ -107,6 +107,8 @@ static void __prepare_to_wait(struct waitqueue_vcpu *wqv) { char *cpu_info = (char *)get_cpu_info(); + ASSERT(wqv->esp == 0); + asm volatile ( #ifdef CONFIG_X86_64 "push %%rax; push %%rbx; push %%rcx; push %%rdx; push %%rdi; " @@ -173,14 +175,13 @@ void prepare_to_wait(struct waitqueue_head *wq) struct waitqueue_vcpu *wqv = curr->waitqueue_vcpu; ASSERT(!in_atomic()); - ASSERT(list_empty(&wqv->list)); + __prepare_to_wait(wqv); + ASSERT(list_empty(&wqv->list)); spin_lock(&wq->lock); list_add_tail(&wqv->list, &wq->list); vcpu_pause_nosync(curr); spin_unlock(&wq->lock); - - __prepare_to_wait(wqv); } void finish_wait(struct waitqueue_head *wq) -- 2.30.2